﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Xml.Linq;

namespace EquationsBankReader.EquationsRead
{
    public class EquationsReader
    {
        #region private fields
        private IEnumerable<FileInfo> FilesPaths;
        private DirectoryInfo EquationsDirectory;
        private List<string> FileFullPath;
        private List<XML_Parser> EquationsFiles;
        #endregion
        
        public EquationsReader(string EquationsPath)
        {
            EquationsFiles = new List<XML_Parser>();
            GetFiles(EquationsPath);
        }
        
        // get equations xml files
        public void GetFiles(string EquationsPath)
        {
            if (EquationsPath != null && EquationsPath != "")
            {
                EquationsDirectory = new DirectoryInfo(EquationsPath);
                FileFullPath = new List<string>();
                //Getting all the equations
                FilesPaths = EquationsDirectory.EnumerateFiles("*Equation.xml", SearchOption.AllDirectories);
                // Parsing all the equations files
                foreach (FileInfo file in FilesPaths)
                {
                    //Creating list of all possible Equations after parsing them
                    XML_Parser Equation = new XML_Parser(file);
                    EquationsFiles.Add(Equation);
                }
                // adding the equations to database
                Xml_Read CreateDataBase = new Xml_Read();
                CreateDataBase.AddListToDataBase(EquationsFiles);
            }
        }
        /* To create the data base tables
        public void CreatTables(IEnumerable<FileInfo> FilesPaths)
        {
            int FileIndex = 0;
            // Reading all the files
            foreach (FileInfo file in FilesPaths)
            {
                FilePath = file.DirectoryName;
                FileName = file.Name;
                FileFullPath = FilePath.Split('\\').ToList<string>();
                // Getting file fields path
                for (int FieldIndex = FileFullPath.IndexOf("Fields"); FieldIndex < FileFullPath.ToArray().Length; FieldIndex++)
                {
                    
                }
                FileIndex++;
            }
        }*/

    }
}
